package cn.explink.dop.entity.vo;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnore;

import cn.explink.dop.enums.pub.EnableEnum;
import cn.explink.eap.core.common.entity.IdEntity;

/**
 * 店面实体
 *
 * @author firefly 2015-2-27 09:56
 *
 */
@Entity
@Table(name = "bd_storefront")
public class StorefrontVO extends IdEntity implements java.io.Serializable {

	private static final long serialVersionUID = 7916153802764421127L;
	/** 店面名称 */
	private String stoName;
	/** 店面地址 */
	private String stoAddress;
	/** 店面坐标 */
	private String stoCoordinate;
	/** 营业开始时间 */
	private String stoStarttime;
	/** 营业结束时间 */
	private String stoEndtime;
	/**
	 * 状态：1：启用 2：停用 3：删除
	 */
	private Integer stoStatus;
	/** 所属餐厅 */

	private RestaurantVO restaurant;

	private List<DeliveryManVO> deliveryManList;

	private List<AreaVO> areaList;

	@Column(name = "sto_name", nullable = true, length = 200)
	public String getStoName() {
		return this.stoName;
	}

	public void setStoName(String stoName) {
		this.stoName = stoName;
	}

	@Column(name = "sto_address", nullable = true, length = 500)
	public String getStoAddress() {
		return this.stoAddress;
	}

	public void setStoAddress(String stoAddress) {
		this.stoAddress = stoAddress;
	}

	@Column(name = "sto_coordinate", nullable = true, length = 100)
	public String getStoCoordinate() {
		return this.stoCoordinate;
	}

	public void setStoCoordinate(String stoCoordinate) {
		this.stoCoordinate = stoCoordinate;
	}

	@Column(name = "sto_starttime", nullable = true, length = 10)
	public String getStoStarttime() {
		return this.stoStarttime;
	}

	public void setStoStarttime(String stoStarttime) {
		this.stoStarttime = stoStarttime;
	}

	@Column(name = "sto_endtime", nullable = true, length = 10)
	public String getStoEndtime() {
		return this.stoEndtime;
	}

	public void setStoEndtime(String stoEndtime) {
		this.stoEndtime = stoEndtime;
	}

	@Column(name = "sto_status", columnDefinition = "int default 1")
	public Integer getStoStatus() {
		return this.stoStatus;
	}

	public void setStoStatus(Integer stoStatus) {
		this.stoStatus = stoStatus;
	}
	
	@Transient
	public String getStoStatusText() {
		if(EnableEnum.Enable.getValue()==this.stoStatus){
			return EnableEnum.Enable.getText();
		}
		return EnableEnum.Unable.getText();
	}

	@JsonIgnore
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "restaurant_id")
	public RestaurantVO getRestaurant() {
		return this.restaurant;
	}

	public void setRestaurant(RestaurantVO restaurant) {
		this.restaurant = restaurant;
	}

	@Transient
	public String getRestaurantName() {
		if (this.restaurant != null) {
			return this.restaurant.getResName();
		}
		return "";
	}

	@JsonIgnore
	@ManyToMany(targetEntity = DeliveryManVO.class, cascade = CascadeType.ALL)
	@JoinTable(name = "bd_deliveryman_storefront", joinColumns = @JoinColumn(name = "storefront_id"), inverseJoinColumns = @JoinColumn(name = "deliveryman_id"))
	public List<DeliveryManVO> getDeliveryManList() {
		return this.deliveryManList;
	}

	public void setDeliveryManList(List<DeliveryManVO> deliveryManList) {
		this.deliveryManList = deliveryManList;
	}

	@Transient
	public List<String> getDeliveryManIdList() {
		List<String> deliveryManIdList = new ArrayList<String>();
		if ((this.deliveryManList != null) && (this.deliveryManList.size() > 0)) {
			for (DeliveryManVO deliveryManVO : this.deliveryManList) {
				deliveryManIdList.add(deliveryManVO.getId());
			}
		}
		return deliveryManIdList;
	}

	@Transient
	public String getDeliverymanName() {
		String deliverymanName = "";
		if ((this.deliveryManList != null) && (this.deliveryManList.size() > 0)) {
			for (DeliveryManVO deliveryManVO : this.deliveryManList) {
				deliverymanName += " " + deliveryManVO.getDelName();
			}
		}
		return deliverymanName;
	}

	@JsonIgnore
	@ManyToMany(targetEntity = AreaVO.class, cascade = CascadeType.ALL)
	@JoinTable(name = "bd_storefront_area", joinColumns = @JoinColumn(name = "storefront_id"), inverseJoinColumns = @JoinColumn(name = "area_id"))
	public List<AreaVO> getAreaList() {
		return this.areaList;
	}

	public void setAreaList(List<AreaVO> areaList) {
		this.areaList = areaList;
	}

	@Transient
	public List<String> getAreaIdList() {
		List<String> areaIdList = new ArrayList<String>();
		if ((this.areaList != null) && (this.areaList.size() > 0)) {
			for (AreaVO areaVO : this.areaList) {
				areaIdList.add(areaVO.getId());
			}
		}
		return areaIdList;
	}

	@Transient
	public String getAreaName() {
		String areaName = "";
		if ((this.areaList != null) && (this.areaList.size() > 0)) {
			for (AreaVO areaVO : this.areaList) {
				areaName += " " + areaVO.getBaseAreaName();
			}
		}
		return areaName;
	}

}
